package com.dingwei.superiordiary.adapter.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bobomee.android.mentions.edit.util.FormatRangeManager;
import com.bobomee.android.mentions.text.MentionTextView;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.bean.CommentBean;
import com.dingwei.superiordiary.parser.Parser;
import com.dingwei.superiordiary.utils.SpanUtils;
import com.dingwei.superiordiary.utils.SpannableStringUtils;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.T;

import org.sufficientlysecure.htmltextview.ClickableTableSpan;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author 南柯一梦丶
 * Created time 2018/10/19.
 * Personal signature 余生还长 何必慌张
 * Page description :
 * .::::.
 * .::::::::.
 * :::::::::::
 * ..:::::::::::'
 * '::::::::::::'
 * .::::::::::
 * '::::::::::::::..
 * ..::::::::::::.
 * ``::::::::::::::::
 * ::::``:::::::::'        .:::.
 * ::::'   ':::::'       .::::::::.
 * .::::'      ::::     .:::::::'::::.
 * .:::'       :::::  .:::::::::' ':::::.
 * .::'        :::::.:::::::::'      ':::::.
 * .::'         ::::::::::::::'         ``::::.
 * ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 * '.:::::'                    ':'````..
 */
public class SecondaryCommentAdaper extends RecyclerArrayAdapter<CommentBean.DataBean.ListBean.SubBean> {
    private XXInterface xxInterface;

    public void setXXInterface(XXInterface xxInterface) {
        this.xxInterface = xxInterface;
    }

    public SecondaryCommentAdaper(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new FindDetailsEvaluationItemHolder(parent);
    }
    private FormatRangeManager mRangeManager;
    private Parser mTagParser = new Parser();
    class FindDetailsEvaluationItemHolder extends BaseViewHolder<CommentBean.DataBean.ListBean.SubBean> {


        @Bind(R.id.tv_content)
        MentionTextView tvContent;
        @Bind(R.id.img_like)
        ImageView imgLike;
        @Bind(R.id.tv_like_num)
        TextView tvLikeNum;
        @Bind(R.id.like_layout)
        LinearLayout likeLayout;
        @Bind(R.id.tv_add_time)
        TextView tvAddTime;

        public FindDetailsEvaluationItemHolder(ViewGroup parent) {
            super(parent, R.layout.item_details_comment_item);
            ButterKnife.bind(this, itemView);
            tvContent.setMovementMethod(new LinkMovementMethod());
            tvContent.setParserConverter(mTagParser);
        }

        @Override
        public void setData(final CommentBean.DataBean.ListBean.SubBean data) {
            super.setData(data);
//            ClickableSpan span = new ClickableSpan() {
//                @Override
//                public void onClick(View view) {
//                    xxInterface.uers(getDataPosition());
//                    T.showShort(BaseActivity.context, "-------------------");
//                }
//            };
//            TextPaint ts = new TextPaint();
//            ts.linkColor = ContextCompat.getColor(BaseActivity.context, R.color.selected_bg_color);
//            ts.setUnderlineText(true);
//            span.updateDrawState(ts);
            String s = data.content.replaceAll("'>", "'>@");
            s = " <user id='" + data.consumer_id+ "' name='" + data.nickname + "'>" + data.nickname + "</user>: " + s;
            tvContent.setText(s);


            tvAddTime.setText(data.addtime);
            if (data.is_liked == 1) {
                imgLike.setImageResource(R.mipmap.ic_comment_liked);
            } else {
                imgLike.setImageResource(R.mipmap.ic_comment_not_like);
            }
            tvLikeNum.setText(data.likes);
            likeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (xxInterface != null) {
                        xxInterface.like(getDataPosition());
                    }
                }
            });
        }
    }

    public interface XXInterface {
        void like(int position);

        void uers(int position);

    }
}
